JDK 8 : JAVA SDK
2016/06/19 |
Install Java SE Development Kit 8 (JDK8) and build Java Environment.
|
|
[1] | Download and install JDK 8. Make sure the latest version and source URL of JDK on Oracle download site. |
root@dlp:~#
curl -LO -H "Cookie: oraclelicense=accept-securebackup-cookie" \
"http://download.oracle.com/otn-pub/java/jdk/8u91-b14/jdk-8u91-linux-x64.tar.gz"
root@dlp:~#
tar zxvf jdk-8u91-linux-x64.tar.gz root@dlp:~# mkdir /usr/java root@dlp:~# mv jdk1.8.0_91 /usr/java/jdk1.8.0_91
root@dlp:~#
vi /etc/profile # add follows to the end
export JAVA_HOME=/usr/java/jdk1.8.0_91 export PATH=$PATH:$JAVA_HOME/bin export CLASSPATH=.:$JAVA_HOME/jre/lib:$JAVA_HOME/lib:$JAVA_HOME/lib/tools.jar source /etc/profile
|
[2] | If another version of JDK had been installed, change the default like follows. |
root@dlp:~#
root@dlp:~# update-alternatives --install "/usr/bin/java" "java" "/usr/java/jdk1.8.0_91/bin/java" 1 root@dlp:~# update-alternatives --install "/usr/bin/javac" "javac" "/usr/java/jdk1.8.0_91/bin/javac" 1 root@dlp:~# update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/java/jdk1.8.0_91/bin/javaws" 1
update-alternatives --config java There are 2 choices for the alternative java (providing /usr/bin/java). Selection Path Priority Status ------------------------------------------------------------ * 0 /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java 1071 auto mode 1 /usr/java/jdk1.8.0_91/bin/java 1 manual mode 2 /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java 1071 manual mode # select 1 Press enter to keep the current choice[*], or type selection number: 1 update-alternatives: using /usr/java/jdk1.8.0_91/bin/java to provide /usr/bin/java (java) in manual mode # change like above, too root@dlp:~# update-alternatives --config javac root@dlp:~# update-alternatives --config javaws |
[3] | Create a test program and make sure if it works normally. |
root@dlp:~#
vi day.java import java.util.Calendar; class day { public static void main(String[] args) { Calendar cal = Calendar.getInstance(); int year = cal.get(Calendar.YEAR); int month = cal.get(Calendar.MONTH) + 1; int day = cal.get(Calendar.DATE); int hour = cal.get(Calendar.HOUR_OF_DAY); int minute = cal.get(Calendar.MINUTE); System.out.println(year + "/" + month + "/" + day + " " + hour + ":" + minute); } } # compile root@dlp:~# javac day.java # run root@dlp:~# java day 2016/6/19 14:10 |